{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1a8b09f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "0cf201e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def calNewW(wi,h,si):\n",
    "    return wi + h * si"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "937a8bca",
   "metadata": {},
   "outputs": [],
   "source": [
    "def f1(Y):\n",
    "    return Y[1]\n",
    "\n",
    "def f2(Y,R,L,C):\n",
    "    return - R / L * Y[1] - 1 / L / C * Y[0] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c71c8f88",
   "metadata": {},
   "outputs": [],
   "source": [
    "R = 0.1\n",
    "L = 1\n",
    "C = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "08eda8b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "freq = 1 / (2 * np.pi * np.sqrt(L * C))\n",
    "timeStep = 5 / freq\n",
    "h = 1 / (100 * freq)\n",
    "t = np.arange(0,timeStep,h)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "c7188711",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y = np.zeros((t.size,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "b0e48855",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y[0] = [0,-2]\n",
    "for i in range(t.size - 1):\n",
    "    Y[i,0] = calNewW(Y[i-1,0],h,f1(Y[i-1]))\n",
    "    Y[i,1] = calNewW(Y[i-1,1],h,f2(Y[i-1],R,L,C))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "f4617430",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x2040f3d0b50>]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     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0+4DXb8gCL5EkO4DXAR9YMdzmGiR5CfB7wAcBquqZqvpvGl0DYDPwc0k2Ay8EztDr/J9TpxBsB06v2F4cxlpIMge8CngEeFlVnYXlWABXb+DSLoX3AW8HfrhirNM1+CVgCfjH4fbYB5K8iCbXoKq+Bfwt8E3gLPBUVX2GJuc/iU4hyJixFp+dTfJi4OPAW6rq+xu9nkspyc3Ak1V1fKPXsoE2A9cBd1fVq4D/odFtkOHe/wFgF3AN8KIkb9jYVT2/dArBIrBzxfYOlt8e/lRL8gKWI/CRqvrEMPydJNuG/duAJzdqfZfAq4Fbknyd5duBr0nyYXpdg0VgsaoeGbY/xnIYulyD1wL/WVVLVfW/wCeA36HP+a+pUwgeBXYn2ZVkC8u/LDq6wWu6qJKE5fvCJ6vqvSt2HQUODo8PAp+61Gu7VKrqHVW1o6rmWP5n/rmqegO9rsG3gdNJfnUYugH4Kn2uwTeB65O8cPiZuIHl35d1Of81tfrL4iQ3sXy/eBNwb1X99cau6OJK8rvAvwFf4cf3x9/J8u8JPgpcy/IPyR9V1X9tyCIvoSS/D7ytqm5O8gs0ugZJfovlX5ZvAU4Bt7P8P4ItrkGSdwN/zPIn6b4I/BnwYpqc/1pahUCS9JM63RqSJI1hCCSpOUMgSc0ZAklqzhBIUnOGQJKaMwSS1Nz/Afzfve66X1o3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(t,Y[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cef4be4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
